package com.lgkj.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lgkj.R;
import com.lgkj.bean.BarberShopListBean;
import com.lgkj.utils.CommonUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/6/19 0019.
 */

public class HomeShopAdapter extends BaseAdapter {
    private Context context;

    private List<BarberShopListBean.DataBeanX.DataBean> dataBeans;

    public void setDataBeans(List<BarberShopListBean.DataBeanX.DataBean> dataBeans) {
        if (dataBeans != null) {
            this.dataBeans = dataBeans;
        }
    }

    public HomeShopAdapter(Context context) {
        this.context = context;
        this.dataBeans = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return dataBeans.size();
    }

    @Override
    public BarberShopListBean.DataBeanX.DataBean getItem(int i) {
        return dataBeans.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_home_shop, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        CommonUtils.LoadImage(context, viewHolder.ivImg, dataBeans.get(i).getBarbershop_img(), R.mipmap.defult_banner);
        viewHolder.tvTitle.setText(dataBeans.get(i).getBarbershop_name());
        viewHolder.tvDesc.setText(dataBeans.get(i).getBarbershop_address());
        String phone = dataBeans.get(i).getBarbershop_tel();
        if (phone != null && phone.length()<7) {
            phone = "商家暂无添加电话号码";
        }
        viewHolder.tvPhone.setText(phone);


        return view;
    }

    static class ViewHolder {
        @BindView(R.id.iv_img)
        ImageView ivImg;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_km)
        TextView tvKm;
        @BindView(R.id.tv_desc)
        TextView tvDesc;
        @BindView(R.id.tv_phone)
        TextView tvPhone;
        @BindView(R.id.tv_yuding)
        TextView tvYuding;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
